package net.system.sys.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import net.core.base.dao.CommonDAO;
import net.core.common.StrUtils;
import net.system.base.bean.SSysdict;
import net.system.base.bean.SSysdictExample;
import net.system.sys.dao.SSysdictDAO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DictServiceImpl implements IDictService {
	@Autowired
	private SSysdictDAO dao;
	@Autowired
	private CommonDAO commonDAO;
	@Autowired
	private ICommService commService;
	@Override
	public List<SSysdict> selectDict() {
		SSysdictExample example = new SSysdictExample();
		SSysdictExample.Criteria c = example.createCriteria();
		c.andRecStatusEqualTo("1");
		List<SSysdict> list = dao.selectByExample(example);
		return list;
	}

	@Override
	public void saveDict(HashMap reqMap) {
		String table = "S_SYSDICT";
		String[] aSaveColumn = { "SD_TYPE", "SD_NAME", "SD_VALUE", "SD_DESC", "SD_ISDT" };
		String[] aSaveDefault = { "REC_ID","REC_PERSON", "REC_TIME", "REC_STATUS" };
		String sql = "insert into <table>(<columns>)VALUES(<values>)";

		// 拼装值
		String sFormValue = "";
		for (int i = 0; i < aSaveColumn.length; i++) {
			sFormValue += ",'" + reqMap.get(aSaveColumn[i]) + "'";
		}
		// 系统字段
		String sSeq = commService.getSeq("dict");
		sFormValue += ",'"+sSeq+"','dum',now(),'1'";
		sql = sql.replace("<table>", table).replace(
				"<columns>",
				StrUtils.transArrayToString(aSaveColumn)+","
						+ StrUtils.transArrayToString(aSaveDefault));
		sql = sql.replace("<values>", sFormValue.substring(1));
		System.out.println(sql);
		commonDAO.insertSql(sql);
	}

}
